﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_decedent_works : BasePage
{
    protected int id = 0;
    protected int IndexPage = 1;
    protected string WhereStr = "";
    protected UserPhoto UPhtoBll = new UserPhoto();
    protected UserPhoto_Model Uphoto_model = new UserPhoto_Model();
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (id <= 0)
        {
            ShowMsgBack("参数传递错误！");
            Response.End();
        }


        if (Request["page"] != null)
        {
            IndexPage = StringHelper.isNumber_int(Request["page"].ToString()) == 0 ? 1 : StringHelper.isNumber_int(Request["page"].ToString());
        }

        Base_CurrPath = Base_CurrPath + " >> 会员管理中心 >> 纪念馆管理 >> 历史相册";
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/decedent_works_" + id + ".Aspx", "", true);
        WhereStr = " isdel=0 and classid=2 and Types=" + id + " and ChannelID=" + (int)Channel_Type.memorial + " and    CreateId=" + Base_GetLoginInfo.GetUserID;

        if (!Page.IsPostBack)
        {
            bind();
        }

    }

    protected void bind()
    {
        this.AspNetPager1.UrlRewritePattern = "decedent_works_" + id + "_{0}.Aspx";
        this.AspNetPager1.PageSize = 18;
        Pager p = new Pager();
        p.PageIndex = IndexPage;
        p.Ident = "id";
        p.Obj = Repeater1;
        p.Orderfld = "Addtime";
        p.OrderType = "desc";
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.PageSize = this.AspNetPager1.PageSize;
        p.TableName = "UserPhoto";
        p.WhereStr = WhereStr;
        p.ControlBind();
        this.AspNetPager1.RecordCount = p.recordcount();

    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (Repeater1.Items.Count == 0)//显示的数据项为0 既是没有数据
            {
                ((Panel)e.Item.FindControl("Panel_Noting")).Visible = true;

            }
        }

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string PhotoID = "";
        if (Request["PhotoID"] != null)
        {
            PhotoID = Request["PhotoID"].ToString();
        }
        if (PhotoID == "")
        {
            ShowMsgBack("参数传递错误!");
            Response.End();
        }
        string[] IdArry = StringHelper.SplitString(PhotoID, ",");

        foreach (string str in IdArry)
        {
            if (StringHelper.strNull(str) == "") { break; }
            if (StringHelper.isNumber_int(str) <= 0) { break; }
            Uphoto_model = UPhtoBll.GetModel(StringHelper.isNumber_int(str));

            if (UPhtoBll.delete(StringHelper.isNumber_int(str)) > 0)
            {
                StringHelper.delFile(Uphoto_model.PhotoUrl);
            }
        }
        Response.Redirect("decedent_works_" + id + ".Aspx");
        Response.End();
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {


        if (e.CommandName == "delinfo")
        {
            string PhotoID = e.CommandArgument.ToString();

            if (PhotoID == "")
            {
                ShowMsgBack("参数传递错误!");
                Response.End();
            }


            if (StringHelper.strNull(PhotoID) == "")
            {

                ShowMsgBack("参数传递错误!");
                Response.End();

            }
            if (StringHelper.isNumber_int(PhotoID) <= 0)
            {

                ShowMsgBack("参数传递错误!");
                Response.End();

            }
            Uphoto_model = UPhtoBll.GetModel(StringHelper.isNumber_int(PhotoID));
            if (UPhtoBll.delete(StringHelper.isNumber_int(PhotoID)) > 0)
            {
                StringHelper.delFile(Uphoto_model.PhotoUrl);
            }

            Response.Redirect("decedent_works_" + id + ".Aspx");
            Response.End();

        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }
}